//    Copyright (C) Kherty.  All rights reserved.
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Reflection;
using OpenLS.Core.Notification;
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public class Scaling : ViewModelBase, IOfficeXmlSerializable
    {
        private double? logBase;
        private double? maximum;
        private double? minimum;

        private AxisOrientation orientation;

        public double? LogBase
        {
            get { return logBase; }
            set
            {
                logBase = value;
                notifyPropertyChanged("LogBase");
            }
        }

        public AxisOrientation Orientation
        {
            get { return orientation; }
            set
            {
                orientation = value;
                notifyPropertyChanged("Orientation");
            }
        }

        public double? Minimum
        {
            get { return minimum; }
            set
            {
                minimum = value;
                notifyPropertyChanged("Minimum");
            }
        }

        public double? Maximum
        {
            get { return maximum; }
            set
            {
                maximum = value;
                notifyPropertyChanged("Maximum");
            }
        }


        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("scaling"))
            {
                LogBase = c.ReadOptionalElementDoubleAttribute("logBase");
                Orientation =
                    c.ReadOptionalElementEnumAttribute("orientation", AxisOrientation.MinimumToMaximum);
                Maximum = c.ReadOptionalElementDoubleAttribute("max");
                Minimum = c.ReadOptionalElementDoubleAttribute("min");
                c.WarnIf("crtExt");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("scaling"))
            {
                c.WriteOptionalElementDoubleAttribute("logBase", LogBase);
                //\\c.WriteOptionalElementEnumAttribute<AxisOrientation>("orientation", Orientation, AxisOrientation.MinimumToMaximum, AxisOrientation.MinimumToMaximum);
                c.WriteElementEnumAttribute("orientation", Orientation);
                c.WriteOptionalElementDoubleAttribute("max", Maximum);
                c.WriteOptionalElementDoubleAttribute("min", Minimum);
                c.WarnIf("crtExt");
            }
        }

        #endregion


    }
}